// ==UserScript==
// @name			Ikariam - Alliance Chat
// @version			1.0
// @date			2008-08-15
// @namespace		archeorbiter.googlecode.com
// @description		Version 1.0 - Adds an integrated chat widget to the right side of the window.
// @include			http://s*.ikariam.tld/*
// @include			http://s*.ikariam.com.pt/*
// @include			http://s*.ikariam.co.il/*
// @include			http://s*.fi.ikariam.com/*
// ==/UserScript==


GM_addStyle('#ac_chatbox { width: 228px; background: url(http://'+ location.host +'/skin/layout/bg_sidebox.gif) repeat-y; position: fixed; top: 20px; z-index: 999 }' +
			'#ac_tab { width: 26px; height: 100px; background: url(http://archeorbiter.googlecode.com/svn/trunk/projects/scripts/ikariam_alliance_chat/chattab.png) no-repeat; position: absolute; left: -26px; top: 0px}' +
			'#ac_header { height: 24px; padding-top: 2px; background: url(http://'+ location.host +'/skin/layout/bg_sidebox_header.jpg) no-repeat; position: relative; line-height: 24px; text-align: center; font-weight: bold }' +
			'#ac_pin { width: 13px; height: 13px; background-repeat: no repeat; position: absolute; top: 8px; right: 8px }' +
			'#ac_content { margin: 10px 5px 5px }' +
			'#ac_footer {  height: 5px; background: url(http://'+ location.host +'/skin/layout/bg_sidebox_footer.gif) no-repeat }');

var chatFrame = '<iframe width="200" height="500" border="0" frameborder="0" src="http://www.shoutmix.com/?Archonyx"></iframe>';
var pinImg = 'url(http://archeorbiter.googlecode.com/svn/trunk/projects/scripts/ikariam_alliance_chat/pin.png)';
var unPinImg = 'url(http://archeorbiter.googlecode.com/svn/trunk/projects/scripts/ikariam_alliance_chat/pin_a.png)';


function toggleChat() {

	if (chatBox.style.right == '-228px') {
	chatBox.style.right = '0';
	ChatContent.innerHTML = chatFrame;
	} else {
	GM_setValue('ac_pin', false);
	chatBox.style.right = '-228px';
	ChatContent.innerHTML = '';
	}
}

function pinChat() {

	if (pin.style.backgroundImage == pinImg) {
	GM_setValue('ac_pin', true);
	pin.style.backgroundImage = unPinImg;
	pin.title = 'Unpin';
	} else {
	GM_setValue('ac_pin', false);
	pin.style.backgroundImage = pinImg;
	pin.title = 'Pin';
	}
}

var body = document.getElementsByTagName('body')[0];
var chatBox = document.createElement('div');
chatBox.id = 'ac_chatbox';
chatBox.innerHTML =
	'<div id="ac_tab"></div>' +
	'<div id="ac_header">Alliance Chat' +
		'<a id="ac_pin"></a>' +
	'</div>' +
	'<div id="ac_content"></div>' +
	'<div id="ac_footer"></div>'
body.appendChild(chatBox);

var ChatContent = document.getElementById('ac_content');
var pin = document.getElementById('ac_pin');
pin.style.backgroundImage = pinImg;
pin.title = 'Pin';
pin.addEventListener('click', pinChat, false);

if (GM_getValue('ac_pin', false) == false) {
chatBox.style.right = '-228px';
} else {
chatBox.style.right = '0';
ChatContent.innerHTML = chatFrame;
pin.style.backgroundImage = unPinImg;
pin.title = 'Unpin';
}

var tab = document.getElementById('ac_tab');
tab.addEventListener('click', toggleChat, false);
